package com.junction;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import javax.annotation.PreDestroy;
import javax.swing.*;

import com.junction.pojo.TaskPojo;
import com.junction.thread.KeyboardListenerThread;
import com.junction.thread.ScreenCaptureThread;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import com.junction.cache.CacheUtil;
import com.junction.thread.CameraThread;
import com.junction.util.CameraPush;
//import com.junction.util.TimerUtil;

@SpringBootApplication
public class CameraServerApplication implements CommandLineRunner {



	private static Logger logger = LoggerFactory.getLogger(CameraServerApplication.class);

	public static void main(String[] args) {
		// 将服务启动时间存入缓存
//		CacheUtil.STARTTIME = new Date().getTime();
//		final ApplicationContext applicationContext = SpringApplication.run(CameraServerApplication.class, args);
//		// 将上下文传入CameraPush类中，用于检测tcp连接是否正常
//		CameraPush.setApplicationContext(applicationContext);


		SpringApplication.run(CameraServerApplication.class, args);
	}

	@PreDestroy
	public void destory() {
//		System.err.println("释放空间...");
//		// 关闭线程池
//		CameraThread.MyRunnable.es.shutdownNow();
//		// 销毁定时器
//		TimerUtil.timer.cancel();
	}

	@Override
	public void run(String... args) throws Exception {
		TaskPojo task = new TaskPojo();
		task.setFilePath("videos");
		// 执行任务
		ScreenCaptureThread.MyRunnable job = new ScreenCaptureThread.MyRunnable(task);
		ScreenCaptureThread.MyRunnable.es.execute(job);


		logger.info("视频监控任务启动");


		KeyboardListenerThread.MyRunnable keyBoardJob = new KeyboardListenerThread.MyRunnable();
		KeyboardListenerThread.MyRunnable.es.execute(keyBoardJob);


		logger.info("键盘监控任务启动");

	}
}
